package com.gtt.lazy.service.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.gtt.lazy.domain.Notice;
import com.gtt.lazy.service.NoticeService;
import com.gtt.lazy.util.HibernateTemplateUtil;

/**
 * 公告服务实现
 * 
 * @author 高甜甜
 * @date 2009-7-7
 */
public class NoticeServiceImpl implements NoticeService {

	private static final Logger logger = Logger
			.getLogger(NoticeServiceImpl.class);

	private HibernateTemplateUtil hibernateTemplateUtil;

	public int add(Notice notice) {
		if (logger.isDebugEnabled())
			logger.debug("add Notice");
		return (Integer) hibernateTemplateUtil.save(notice);
	}

	public void delete(int id) {
		if (logger.isDebugEnabled())
			logger.debug("delete Notice [ " + id + " ]");
		hibernateTemplateUtil.delete(Notice.class, id);
	}

	public Notice get(int id) {
		return (Notice) hibernateTemplateUtil.get(Notice.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<Notice> list() {
		String hql = "from Notice as n order by n.id desc";
		return hibernateTemplateUtil.find(hql);
	}

	@SuppressWarnings("unchecked")
	public List<Notice> list(int start, int size) {
		String hql = "from Notice as n order by n.id desc";
		return hibernateTemplateUtil.find(hql, start, size);
	}

	public void update(Notice notice) {
		if (logger.isDebugEnabled())
			logger.debug("update Notice [ " + notice.getId() + " ]");
		hibernateTemplateUtil.update(notice);
	}

	public int count() {
		String hql = "select count(*) from Notice as n";
		Long l = (Long) hibernateTemplateUtil.find(hql).get(0);
		return l.intValue();
	}

	public void setHibernateTemplateUtil(
			HibernateTemplateUtil hibernateTemplateUtil) {
		this.hibernateTemplateUtil = hibernateTemplateUtil;
	}

}
